import { request } from '@/plugins/request';

// 获取文章详情
export function getArticle(slug) {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}`
  });
}

// 获取文章评论
export function getArticleComments(slug) {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}/comments`
  });
}

// 关注用户
export function follow(username) {
  return request({
    method: 'POST',
    url: `/api/profiles/${username}/follow`
  });
}

// 关注用户
export function unFollow(username) {
  return request({
    method: 'DELETE',
    url: `/api/profiles/${username}/follow`
  });
}

// 给文章评论
export function addComment(slug, comment) {
  return request({
    method: 'POST',
    url: `api/articles/${slug}/comments`,
    data: {
      comment: { body: comment }
    }
  })
}

// 删除文章评论
export function delComment(slug, id) {
  return request({
    method: 'DELETE',
    url: `api/articles/${slug}/comments/${id}`,
  })
}

// 创建新的文章
export function createArticle(data) {
  return request({
    method: 'POST',
    url: `/api/articles`,
    data
  });
}

// 更新文章
export function editArticle(data, slug) {
  return request({
    method: 'PUT',
    url: `/api/articles/${slug}`,
    data
  });
}

// 删除文章
export function delArticle(slug) {
  return request({
    method: 'DELETE',
    url: `/api/articles/${slug}`
  });
}